ODBCPermissionAttribute Class

Namespace: System.Data.Odbc
Assembly: System.Data.dll

Represents an attribute that demands permission to access ODBC resources. This class cannot be inherited.

Syntax

public sealed sealed class ODBCPermissionAttribute : CodeAccessSecurityAttribute

Applies to: .NET Framework 1.0, 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, 4.8

Remarks

The ODBCPermissionAttribute class is used to grant or deny specific permissions to classes or methods. By applying this attribute, you can control the level of access that code has to ODBC data sources. This is particularly important in managed code environments where security is enforced through code access security (CAS).

The attribute allows you to specify the ODBCPermissionAttribute.OdbcPermissionLevel, which defines the granular level of permission. This could range from no access to full access for connecting to and manipulating ODBC data sources.

Constructors

Properties

Methods

Example

Creating an ODBCPermissionAttribute to grant full permission.


using System;
using System.Security;
using System.Security.Permissions;
using System.Data.Odbc;

public class MyDataAccessClass
{
    // Grant full ODBC permission to this method
    [ODBCPermissionAttribute(SecurityAction.Demand, OdbcPermissionLevel.FullLinked or OdbcPermissionLevel.Connect)]
    public void AccessOdbcDataSource()
    {
        // Code that accesses ODBC data sources goes here
        Console.WriteLine("ODBC access granted.");
    }

    // Example of denying permission
    [ODBCPermissionAttribute(SecurityAction.Deny, OdbcPermissionLevel.All)]
    public void RestrictedOdbcAccess()
    {
        // This code will not be able to access ODBC data sources
        Console.WriteLine("ODBC access denied by attribute.");
    }
}
        

Requirements

Requirement Details
.NET Framework Supported in all versions from 1.0 to 4.8.
Namespaces System.Data.Odbc
Assembly System.Data.dll

See Also